package com.boot.core.util

import com.alibaba.fastjson.JSON
import com.boot.core.result.MsgBean
import com.boot.mgt.dao.mysql.TaHmsPushMapper
import com.boot.mgt.model.TaHmsPush
import com.boot.mgt.model.TaNote
import org.apache.activemq.command.ActiveMQTopic
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.jms.core.JmsMessagingTemplate
import org.springframework.stereotype.Component
import java.util.*

/**
 * Activemq配置
 *
 * @Auther: kawins
 * @Date: 2018/10/20 14:29
 */
@Component
class ActivemqManager {

    @Autowired
    private lateinit var taHmsPushMapper: TaHmsPushMapper

    fun send(msgBean: MsgBean) {
        TaHmsPush().apply {
            policeNumber = msgBean.policeNumber
            accidentReportId = msgBean.accidentReportId
            isSuccess = false
            hmsType = 1
            sendContent = JSON.toJSONString(msgBean)
            sendTime = Date()
            taHmsPushMapper.insertSelective(this)
            msgBean.msgId = this.id
        }
    }

    fun sendNote(taNote: TaNote) {
        TaHmsPush().apply {
            policeNumber = taNote.acceptPoliceNumber
            isSuccess = false
            hmsType = 2
            sendContent = JSON.toJSONString(taNote)
            sendTime = Date()
            taHmsPushMapper.insertSelective(this)
        }
    }

    fun delete(policeNumber: String, accidentReportId: Int) {
        TaHmsPush().apply {
            this.policeNumber = policeNumber
            this.accidentReportId = accidentReportId
            taHmsPushMapper.delete(this)
        }
    }

}